<template>
  <div class="page page_message w100 h100 radius8">
    <template v-if="messageList.length > 0">
      <div class="message_list">
        <div class="item" v-for="o in messageList" :key="o.id">
          <div class="left_avatar">
            <el-avatar :size="42" :src="avatarUrl" />
          </div>
          <div class="right_con">
            <div class="top">
              <div class="createTime">
                {{ $moment(o.createTime).format("YYYY-MM-DD HH:mm") }}
                <span>@神秘帅哥</span>
              </div>
              <div class="address"></div>
            </div>
            <div class="bottom">
              <el-tooltip :content="o.message" placement="bottom" effect="dark">
                <div class="message ellipsis_two">{{ o.message }}</div>
              </el-tooltip>
            </div>
          </div>
        </div>
      </div>
    </template>
    <template v-else>
      <Empty description="还没有任何留言" />
    </template>
    <div class="send_message">
      <el-input
        class="textarea"
        v-model.trim="message"
        maxlength="1024"
        placeholder="说点什么吧……"
        type="textarea"
      />
      <SvgIcon
        @click="handSend"
        iconName="icon-jijianfasong"
        className="pointer icon-jijianfasong"
        size="24px"
      />
    </div>
  </div>
</template>

<script>
import { getMessageList, postMessageList } from "@/api/blog/message"
// 默认头像
import avatar from "../../assets/images/avatar.png"

export default {
  // eslint-disable-next-line vue/multi-word-component-names
  name: "Message",
  props: {},
  components: {},
  emit: [],
  data() {
    return {
      avatarUrl: avatar,
      messageList: [],
      message: ""
    }
  },
  computed: {},
  watch: {},
  methods: {
    async getGetMessageList() {
      const { code, data, msg } = await getMessageList()
      if (code !== 200) {
        return this.$message.error(msg)
      }
      this.messageList = data
    },
    async handSend() {
      if (!this.message) {
        return this.$message.warning("先说点什么吧！")
      }
      const params = {
        message: this.message
      }
      const res = await postMessageList(params)
      if (res.code === 200) {
        this.$message.success("留言成功！")
        this.message = ""
        this.getGetMessageList()
      } else {
        this.$message.error("留言失败！")
      }
    }
  },
  created() {},
  mounted() {
    this.getGetMessageList()
  }
}
</script>

<style lang="scss" scoped>
.page_message {
  position: relative;
  .message_list {
    height: 70%;
    padding: 8px;
    overflow-y: auto;
    .item {
      display: flex;
      align-items: center;
      padding: 8px;
      margin-bottom: 24px;
      border-bottom: 1px solid $border;
      &:last-child {
        border: none;
      }
      /* border-radius: 4px;
      box-shadow: 0px 0px 10px 3px $border; */
      .left_avatar {
        align-self: flex-start;
        width: 42px;
        height: 42px;
      }
      .right_con {
        display: flex;
        flex-direction: column;
        flex: 1;
        padding-left: 8px;
        overflow: hidden;
        .bottom {
          flex: 1;
          display: flex;
          align-items: center;
        }
      }
    }
  }

  .send_message {
    position: absolute;
    bottom: 12px;
    left: 12px;
    right: 12px;
    height: 20%;
    .textarea {
      height: 100%;
      ::v-deep .el-textarea__inner {
        height: 100%;
        padding: 8px;
        text-indent: 2em;
      }
    }
    .icon-jijianfasong {
      position: absolute;
      bottom: 0px;
      right: 8px;
      transform: translateY(-50%);
      color: $info;
    }
  }
}
</style>
import { warn } from "vue"
